package com.zib.vread.sinaweibo.widget;

import android.text.TextUtils;

import com.zib.vread.sinaweibo.entity.Status;

import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class FillContentHelper {

    public static void setSource(Status status) {
        if (TextUtils.isEmpty(status.source)) {
            return;
        }
        if (!status.source.contains("</a>")) {
            return;
        }

        Pattern mpattern = Pattern.compile("<(.*?)>(.*?)</a>");
        Matcher mmatcher = mpattern.matcher(status.source);

        if (mmatcher.find()) {
            String weibocomefrom = mmatcher.group(2);
            status.source = weibocomefrom;
        }
    }


//    public static void setSource(Comment comment) {
//        if (TextUtils.isEmpty(comment.source)) {
//            return;
//        }
//        if (!comment.source.contains("</a>")) {
//            return;
//        }
//        Pattern mpattern = Pattern.compile("<(.*?)>(.*?)</a>");
//        Matcher mmatcher = mpattern.matcher(comment.source);
//
//        if (mmatcher.find()) {
//            String weibocomefrom = mmatcher.group(2);
//            comment.source = weibocomefrom;
//        }
//        if (comment.status != null) {
//            setSource(comment.status);
//        }
//    }

    public static void setImgUrl(Status status) {

        if (status.pic_urls != null && status.pic_urls.size() > 0) {

            if (status.bmiddle_pic_urls.size() > 0) {
                return;
            }
            for (Status.PicUrlsBean picUrlsBean : status.pic_urls) {
                status.thumbnail_pic_urls.add(picUrlsBean.thumbnail_pic);
                status.bmiddle_pic_urls.add(picUrlsBean.thumbnail_pic.replace("thumbnail", "bmiddle"));
                if (!picUrlsBean.thumbnail_pic.endsWith(".gif")) {
                    status.origin_pic_urls.add(picUrlsBean.thumbnail_pic.replace("thumbnail", "large"));
                } else {
                    status.origin_pic_urls.add(picUrlsBean.thumbnail_pic.replace("thumbnail", "bmiddle"));
                }
            }
        }
    }

    public static void setSingleImgSizeType(Status status) {
        if (status.pic_urls != null && status.pic_urls.size() == 1) {
            if (!TextUtils.isEmpty(status.singleImgSizeType)) {
                return;
            }
            status.singleImgSizeType = String.valueOf(new Random().nextInt(3) + 1);
        }
    }
}


